<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mproduct
 *
 * @author sonUIT
 */
class Mproduct extends CI_Model {

    public $matp;
    public $Status_matp;
    public $tentp;
    public $Status_tentp;
    public $hinhanh;
    public $Status_hinhanh;
    public $matl;
    public $Status_matl;
    public $matg;
    public $Status_matg;
    public $namxuatban;
    public $Status_namxuatban;
    public $manxb;
    public $Status_manxb;
    public $sotrang;
    public $Status_sotrang;
    public $caption;
    public $Status_caption;
    public $giagoc;
    public $Status_giagoc;
    public $giaban;
    public $Status_giaban;

    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->matg = "";
        $this->manxb = "";
        $this->matl = "";
        $this->matp = "";
        $this->namxuatban = "";
        $this->sotrang = "";
        $this->tentp = "";
    }

    public function GetAllProducts() {
        return $this->db->get('tacpham')->result_array();
    }

    public function GetSachByMaTg($matg) {
        $this->db->select("*");
        $this->db->from("tacpham");
        $this->db->where("matg", $matg);
        $this->db->limit("10");
        return $this->db->get()->result_array();
    }
    public function GetSachByTheLoai($matl){
        $this->db->select("*");
        $this->db->from("tacpham");
        $this->db->where("matl", $matl);
        $this->db->limit("10");
        return $this->db->get()->result_array();
    }
	 public function GetSachBySachmoi($matl){
        $this->db->select("*");
        $this->db->from("tacpham");
        $this->db->where("sachmoi", $matl);
        $this->db->limit("10");
        return $this->db->get()->result_array();
    }
    public function GetSachBySachNoiBat($matl){
        $this->db->select("*");
        $this->db->from("tacpham");
        $this->db->where("sachnoibat", $matl);
        $this->db->limit("10");
        return $this->db->get()->result_array();
    }
    public function timkiem($tentp,$limit){
        $this->db->select("*");
        $this->db->from("tacpham");
        
        $this->db->like("tentp", $tentp);
        if(!($limit==NULL))
        $this->db->limit($limit);
        return $this->db->get()->result_array();
    }

    public function Get($id) {
        $Issucess = FALSE;
        $this->db->select("*"); //('MATP,TENTP,HINHANH,NAMXB,TP.MANXB,SOTRANG,CAPTION,GIAGOC,GIABAN,TENNXB');
        $this->db->from('tacpham');
        $this->db->where('MATP', $id);
        //var_dump($this->db->get()->result_array());
        $data = $this->db->get()->row_array();
        if (!empty($data)) {
            $this->caption = $data['CAPTION'];
            $this->hinhanh = $data['HINHANH'];
            $this->manxb = $data['MANXB'];
            $this->matg = $data["MATG"];
            $this->matl = $data["MATL"];
            $this->matp = $data['MATP'];
            $this->namxuatban = $data['NAMXUATBAN'];
            $this->sotrang = $data['SOTRANG'];
            $this->tentp = $data['TENTP'];
            $this->giaban = $data["GIABAN"];
            $Issucess = TRUE;
        }
        return $Issucess;
    }

}

?>
